<?php
namespace Home\Controller;
use Think\Controller;
header('content-type:text/html;charset="UTF-8"');
class InformationController extends CommonController {
    public function _initialize(){
        parent::_initialize();
    }
    public function index(){
        $id=$_SESSION['uid'];
        $db=M('mallLogin');
        $data=$db->where("id={$id}")->find();
        if (!empty($data['email'])) {
            $data['name']=$data['email'];
        }
        if (!empty($data['phone'])) {
            $data['name']=$data['phone'];
        }
        $birth=explode("/", $data['birth']);
        $data['year']=$birth[0];
        $data['month']=$birth[1];
        $data['day']=$birth[2];
    	$this->assign('data',$data);

        $dc=M('shopcart');//统计购物车的数量
        $uid=$_SESSION['uid'];
        if (!empty($uid)) {
            $dataCount=$dc->where("uid={$uid}")->select();
            $count=count($dataCount);
            $this->assign('count',$count);  
        }   
       
        $this->display();
    }
    public function saveInformation(){
            $id=$_SESSION['uid'];
            $db=M('mallLogin');
            $data=$db->create();
            $data['birth']="";
            $data['birth']=$_POST['year']."/".$_POST['month']."/".$_POST['day'];
            $ret=$db->where("id={$id}")->save($data);
            $this->success('保存修改成功','',2);

    }
    public function up(){
       
        if ($_FILES['img']['name']!=false) {
            $upload = new \Think\Upload();// 实例化上传类
            $upload->maxSize   =     3145728 ;// 设置附件上传大小
            $upload->exts      =     array('jpg', 'gif', 'png', 'jpeg');// 设置附件上传类型
            $upload->rootPath  =     'Public/Upload/'; // 设置附件上传根目录
            $upload->savePath  =     ''; // 设置附件上传（子）目录
            // 上传文件 
            $info   =   $upload->upload();
            
            if(!$info) {// 上传错误提示错误信息
            $this->error($upload->getError());
            }else{// 上传成功
                $img="/Public/Upload/{$info[0]['savepath']}{$info[0]['savename']}";
                echo $img;
            }
        }
    }
    
}